package controler

import (
	"TodoList/service"
	"github.com/gin-gonic/gin"
)

func Add(c *gin.Context) {
	var service service.AddTodoService
	if err := c.ShouldBind(&service); err == nil {
		res := service.AddTodo()
		c.JSON(200, res)
	} else {
		c.JSON(500, gin.H{
			"message": err.Error(),
		})
	}
}
func Delete(c *gin.Context) {
	var service service.DeleteTodoService
	if err := c.ShouldBind(&service); err == nil {
		res := service.Delete()
		c.JSON(200, res)
	} else {
		c.JSON(500, gin.H{
			"message": err.Error(),
		})
	}
}
func GetList(c *gin.Context) {
	var service service.ListTodoService
	res := service.List()
	c.JSON(200, res)
}

func Update(c *gin.Context) {
	var service service.UpdateTodoService
	if err := c.ShouldBind(&service); err == nil {
		res := service.Update()
		c.JSON(200, res)
	} else {
		c.JSON(500, gin.H{
			"message": err.Error(),
		})
	}
}
